<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 假设数据保存在名为 tasks 的数组中
        const tasks = [
            {
                "projectId": 16,
                "projectName": "吴变工业元宇宙项目一期",
                "milepostId": 491,
                "milepostName": "7.系统上线",
                "taskId": 2982,
                "taskName": "7.1 试运行期间问题收集/处理",
                "taskOwner": "徐子豪",
                "taskParticipant": "徐子豪,李星池,叶妙玲,秦玉国,杜庆金,冯腾飞,马军",
                "startTime": "2024-03-31",
                "endTime": "2024-04-29",
                "taskFinishTime": null,
                "risk": "否",
                "solution": "",
                "riskDescription": "",
                "workingHours": 0,
                "isValid": true
            },
            {
                "projectId": 1381,
                "projectName": "傲林科技测试工厂3水泥配料",
                "milepostId": 4154,
                "milepostName": "数据预处理",
                "taskId": 28794,
                "taskName": "DCS历史数据采集至MQTT",
                "taskOwner": "冯腾飞",
                "taskParticipant": "冯腾飞",
                "startTime": "2024-04-18",
                "endTime": "2024-04-24",
                "taskFinishTime": null,
                "risk": "否",
                "solution": "",
                "riskDescription": "",
                "workingHours": 0,
                "isValid": true
            },
            {
                "projectId": 1381,
                "projectName": "傲林科技测试工厂3水泥配料",
                "milepostId": 4154,
                "milepostName": "数据预处理",
                "taskId": 28795,
                "taskName": "DCS实时数据采集至MQTT",
                "taskOwner": "冯腾飞",
                "taskParticipant": "冯腾飞",
                "startTime": "2024-04-24",
                "endTime": "2024-05-06",
                "taskFinishTime": null,
                "risk": "否",
                "solution": "",
                "riskDescription": "",
                "workingHours": 0,
                "isValid": true
            },
            {
                "projectId": 1381,
                "projectName": "傲林科技测试工厂3水泥配料",
                "milepostId": 4154,
                "milepostName": "数据预处理",
                "taskId": 28798,
                "taskName": "质检历史数据梳理及录入平台",
                "taskOwner": "冯腾飞",
                "taskParticipant": "冯腾飞",
                "startTime": "2024-04-24",
                "endTime": "2024-05-05",
                "taskFinishTime": null,
                "risk": "否",
                "solution": "",
                "riskDescription": "",
                "workingHours": 0,
                "isValid": true
            },
            {
                "projectId": 1381,
                "projectName": "傲林科技测试工厂3水泥配料",
                "milepostId": 4154,
                "milepostName": "数据预处理",
                "taskId": 28799,
                "taskName": "质检实时数据接入",
                "taskOwner": "冯腾飞",
                "taskParticipant": "冯腾飞",
                "startTime": "2024-04-24",
                "endTime": "2024-04-27",
                "taskFinishTime": null,
                "risk": "否",
                "solution": "",
                "riskDescription": "",
                "workingHours": 0,
                "isValid": true
            },
            {
                "projectId": 1381,
                "projectName": "傲林科技测试工厂3水泥配料",
                "milepostId": 4154,
                "milepostName": "数据预处理",
                "taskId": 28800,
                "taskName": "质检数据接入及处理作业完成",
                "taskOwner": "冯腾飞",
                "taskParticipant": "冯腾飞",
                "startTime": "2024-04-18",
                "endTime": "2024-05-05",
                "taskFinishTime": null,
                "risk": "否",
                "solution": "",
                "riskDescription": "",
                "workingHours": 0,
                "isValid": true
            },
            {
                "projectId": 1381,
                "projectName": "傲林科技测试工厂3水泥配料",
                "milepostId": 4155,
                "milepostName": "启动工作",
                "taskId": 28801,
                "taskName": "建团队",
                "taskOwner": "冯腾飞",
                "taskParticipant": "冯腾飞",
                "startTime": "2024-04-13",
                "endTime": "2024-04-24",
                "taskFinishTime": null,
                "risk": "否",
                "solution": "",
                "riskDescription": "",
                "workingHours": 0,
                "isValid": true
            },
            {
                "projectId": 1381,
                "projectName": "傲林科技测试工厂3水泥配料",
                "milepostId": 4155,
                "milepostName": "启动工作",
                "taskId": 28805,
                "taskName": "合同签订",
                "taskOwner": "冯腾飞",
                "taskParticipant": "冯腾飞",
                "startTime": "2024-04-13",
                "endTime": "2024-05-05",
                "taskFinishTime": null,
                "risk": "否",
                "solution": "",
                "riskDescription": "",
                "workingHours": 0,
                "isValid": true
            },
            {
                "projectId": 1381,
                "projectName": "傲林科技测试工厂3水泥配料",
                "milepostId": 4155,
                "milepostName": "启动工作",
                "taskId": 28806,
                "taskName": "项目启动款",
                "taskOwner": "冯腾飞",
                "taskParticipant": "冯腾飞",
                "startTime": "2024-04-13",
                "endTime": "2024-05-21",
                "taskFinishTime": null,
                "risk": "否",
                "solution": "",
                "riskDescription": "",
                "workingHours": 0,
                "isValid": true
            },
            {
                "projectId": 1385,
                "projectName": "江西水泥江西南城南方水泥有限公司水泥配料",
                "milepostId": 4186,
                "milepostName": "启动工作",
                "taskId": 29033,
                "taskName": "项目启动款",
                "taskOwner": "冯腾飞",
                "taskParticipant": "冯腾飞",
                "startTime": "2024-04-02",
                "endTime": "2024-05-13",
                "taskFinishTime": null,
                "risk": "否",
                "solution": "",
                "riskDescription": "",
                "workingHours": 0,
                "isValid": true
            },
            {
                "projectId": 1385,
                "projectName": "江西水泥江西南城南方水泥有限公司水泥配料",
                "milepostId": 4188,
                "milepostName": "系统开发",
                "taskId": 29039,
                "taskName": "需求确认",
                "taskOwner": "冯腾飞",
                "taskParticipant": "冯腾飞",
                "startTime": "2024-04-22",
                "endTime": "2024-05-30",
                "taskFinishTime": null,
                "risk": "是",
                "solution": "",
                "riskDescription": "",
                "workingHours": 0,
                "isValid": true
            },
            {
                "projectId": 1385,
                "projectName": "江西水泥江西南城南方水泥有限公司水泥配料",
                "projectType": "交付",
                "startTime": "2024-04-01",
                "endTime": "2024-10-14",
                "workingHours": 0,
                "isValid": true
            }
        ]

        function validateTasks(tasks) {
            const tip = {
                risk: [],
                valid: []
            }

            tasks.forEach((task, index) => {
                // 校验 isValid 是否为 true
                if (!task.isValid) {
                    tip.valid.push(index);
                }

                // 校验 risk 是否为 '是'，并检查 solution 和 riskDescription 是否为空
                if (task.risk === '是' && (!task.solution || !task.riskDescription)) {
                    tip.risk.push(index);
                }
            });

            return tip;
        }


        const tip = validateTasks(tasks);

        let globalMessage = ""; // 保存全局提示信息

        if (tip.valid.length > 0) {
            globalMessage = `工时有问题：任务${tip.valid.join("、")} 的工时有问题`; // 构建提示信息
            uni.showToast({
                title: `工时有问题：任务${tip.valid.join("、")} 的工时有问题`,
                icon: 'success'
            });
        } else if (tip.risk.length > 0) {
            globalMessage = `任务${tip.risk.join("、")}有问题` // 如果存在风险问题
            // 在这里你可以提交给后端，例如通过 AJAX 请求
            uni.showToast({
                title: `工时有问题：任务${tip.valid.join("、")} 的工时有问题`,
                icon: 'success'
            });
        } else {
            globalMessage = "都通过"; // 如果都通过了
        }

        console.log(globalMessage); // 输出全局提示信息



    </script>
</body>

</html>